<template>
    <div>
        <!-- 面包屑导航 -->
        <breadcrumb></breadcrumb>
        <div class="control">
            <div class="inputItem">
                <div class="title">申诉人</div>
                <div class="inputBox">
                    <el-input v-model="createBy"></el-input>
                </div>
            </div>
            <div class="inputItem">
                <div class="title">审核状态</div>
                <div>
                    <el-select size="small" v-model="auditState" placeholder="请选择">
                        <el-option v-for="item in auditStateArr" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </div>
            </div>

            <!-- 查询 -->
            <el-button type="primary" size="small" icon="el-icon-search" @click="getList1()">查询</el-button>
            <el-button type="plain" size="small" icon="el-icon-refresh-right" @click="clearAll">清空</el-button>
        </div>
        <div class="main">
            <div class="list" ref="getHeight">
                <el-table :data="records" style="width: 100%" ref="table">
                    <el-table-column align="center" width="60px" prop="SerialNumber" label="序号">
                        <template slot-scope="scope">
                            <div>{{ scope.$index + 1 + Number(size) * (pageCurrent - 1) }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="auditState" label="审核状态">
                        <template slot-scope="scope">
                            <!-- 审核状态 0未审核 1 审核通过 2驳回” -->
                            <div class="tagBox">
                                <div class="tag yellow" v-if="scope.row.auditState == 0">
                                    <div class="dian"></div>
                                    <div class="text">未审核</div>
                                </div>

                                <div class="tag green" v-else-if="scope.row.auditState == 1">
                                    <div class="dian"></div>
                                    <div class="text">审核通过</div>
                                </div>
                                <div class="tag red" v-else-if="scope.row.auditState == 2">
                                    <div class="dian"></div>
                                    <div class="text">驳回</div>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="createBy" label="申诉人">
                    </el-table-column>
                    <el-table-column align="center" prop="statementReason" label="申诉原因">
                    </el-table-column>
                    <el-table-column align="center" prop="imageUrls" label="申诉图片" width="300">
                        <template slot-scope="scope">
                            <div class="picBox" v-if="scope.row.imageUrls.length != 0">
                                <el-image class="pic" :src="item" v-for="(item, index) in scope.row.imageUrls" :key="index"
                                    :preview-src-list="scope.row.imageUrls">
                                </el-image>
                            </div>
                            <div v-else-if="scope.row.imageUrls.length == 0">暂无图片</div>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="videoUrls" label="申诉视频">
                        <template slot-scope="scope">
                            <div v-if="scope.row.videoUrls.length != 0" class="urlBox">
                                <a class="urlText" :href="item" v-for="(item, i) in scope.row.videoUrls" :key="i"
                                    target="_blank">视频{{ i + 1 }}</a>
                            </div>

                            <div v-else>暂无视频</div>
                        </template>
                    </el-table-column>


                    <el-table-column align="center" prop="auditUser" label="审核人">
                        <template slot-scope="scope">
                            <div>{{ scope.row.auditUser || '--.--' }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="auditTime" label="审核时间">
                        <template slot-scope="scope">
                            <div>{{ scope.row.auditTime || '--.--' }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="createTime" label="申述时间">
                    </el-table-column>
                    <el-table-column align="center" label="操作">
                        <template slot-scope="scope">
                            <div>
                                <el-button type="text" size="small" v-if="scope.row.auditState == 0"
                                    @click="showDialog(scope.row.behaviorStatementId)">审核</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- 分页 -->
            <div class="paginationBox">
                <el-pagination @current-change="changePages($event)" class="pagination" background
                    layout="slot,prev, pager, next" :total="data.total * 1" :page-size="data.size * 1" :pager-count="5">
                    <template slot>
                        <span style="
                  color: #686868;
                  font-size: 12px;
                  margin-right: 20px;
                  display: inline-block;
                ">共{{ data.total }}条,每页{{ data.size }}条</span>
                    </template>
                </el-pagination>
            </div>
        </div>

        <el-dialog class="dialog" title="申诉审核" :visible.sync="dialogVisible" width="560px">
            <el-form :model="Form" :rules="Rules" ref="Form" label-width="100px">
                <!-- 通过1 不通过2 -->
                <el-form-item label="申诉审核" prop="auditState">
                    <el-radio-group v-model="Form.auditState">
                        <el-radio :label="1">通过</el-radio>
                        <el-radio :label="2">不通过</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="备注" prop="remark" v-if="Form.auditState == 2">
                    <el-input type="textarea" resize="none" :rows="4" placeholder="请输入内容" v-model="Form.remark">
                    </el-input>
                </el-form-item>
                <div style="display: flex; justify-content: flex-end">
                    <button class="cancelBtn" @click="dialogVisible = false">取 消</button>
                    <button class="submitBtn" type="primary" @click="submitForm('Form')">确 定</button>
                </div>
            </el-form>
        </el-dialog>

    </div>
</template>
  
<script>
import breadcrumb from "@/components/breadcrumb.vue";
import httpApi from "@/http";

export default {
    data() {
        return {
            createBy: "",//申诉人
            auditState: "",//审核状态
            auditStateArr: [{ label: "未审核", value: 0 }, { label: "审核通过", value: 1 }, { label: "驳回", value: 2 }],
            records: [],
            data: {},
            pageCurrent: 1, //当前页码
            size: "10",
            Form: {
                auditState: 1,
                remark: ''
            },
            behaviorStatementId: "",//审核申诉id
            Rules: {
                auditState: [{ required: true, message: '请选择', trigger: 'change' }],
                remark: [{ required: true, message: '请填写', trigger: 'change' }],
            },
            dialogVisible: false,
        };
    },

    methods: {

        showDialog(behaviorStatementId) {
            this.behaviorStatementId = behaviorStatementId
            this.dialogVisible = true
        },
        clearAll() {
            this.createBy = ''
            this.auditState = ''
            this.getList1()
        },
        changePages(val) {
            this.pageCurrent = val;
            this.getList();
        },
		getList1(){
			this.pageCurrent=1;
			this.getList();
		},
        getList() {
            let params = {
                size: this.size,
                current: this.pageCurrent,
                createBy: this.createBy,
                auditState: this.auditState
            };

            httpApi.driverApi.getBehaviorStatementList(params).then((res) => {
                if (res.data.code == 200) {
                    //分离图片 和视频的文件,分别放置在两个数组
                    res.data.data.records.forEach(item => {
                        if (item.statementUrls != null && item.statementUrls != '') {  //保证后端没给我空 或者null
                            let arr = item.statementUrls.split(',')  //字符串,隔开 生成数组
                            item.videoUrls = []
                            item.imageUrls = []
                            arr.forEach((item2, index) => {
                                let fileAfterName = item2.slice(item2.lastIndexOf(".") + 1, item2.length) //拿到后缀名
                                console.log(fileAfterName); if (fileAfterName == 'mp4') {//MP4的放在视频数组
                                    arr.splice(index, 1)
                                    item.videoUrls.push(item2)
                                } else if (fileAfterName != 'mp4') {
                                    item.imageUrls.push(item2)
                                }
                            })

                        }
                    })





                    this.records = res.data.data.records;
                    console.log('list', this.records);
                    this.data = res.data.data;
                }
                // console.log(res.data.data);
                // console.log('待认证列表数据', res.data.data.records);
            });
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let params = {
                        auditState: this.Form.auditState,
                        remark: this.Form.remark,
                        behaviorStatementId: this.behaviorStatementId
                    }
                    console.log(this.Form);
                    httpApi.driverApi.behaviorStatement(params).then(res => {
                        if (res.data.code == 200) {
                            this.$message.success('操作成功,审核通过')
                            this.dialogVisible = false
                            this.getList()
                        } else if (res.data.code == 202) {
                            this.$message.success('操作成功,审核不通过')
                            this.dialogVisible = false
                            this.getList()
                        }
                    })
                } else {
                    this.$message.error('请填写信息')
                    return false;
                }
            });
        },
        // 记录滚动距离
        scrollEvent(res) {
            this.$route.meta.scrollTop = res.target.scrollTop
        },
    },
    activated() {
        //组件激活时监听表格滚动条位置,
        this.$refs.table.bodyWrapper.addEventListener('scroll', this.scrollEvent, false)
        // 激活设置滚动位置
        this.$refs.table.bodyWrapper.scrollTop = this.$route.meta.scrollTop
    },
    beforeRouteLeave(to, from, next) {
        // 为了节省资源，再离开页面的时候关闭对于scroll事件的监听
        this.$refs.table.bodyWrapper.removeEventListener('scroll', this.scrollEvent)
        next()
    },


    mounted() {
        this.getList();
    },

    components: {
        breadcrumb,
    },
};
</script>
  
<style lang="scss" scoped>
.control {
    height: 76px;
    width: 100%;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 0 29px;
    margin-bottom: 8px;

    .inputItem {
        display: flex;
        align-items: center;
        margin-right: 23px;

        >.title {
            color: #262626;
            font-size: 12px;
            margin-right: 7px;
        }

        >.inputBox {
            width: 160px;

            ::v-deep .el-input__inner {
                height: 32px;
                font-size: 12px;
            }

            ::v-deep .el-input__inner::placeholder {
                color: #c3c3c3;
                font-size: 12px;
            }
        }
    }
}

.main {
    width: 100%;
    height: calc(100vh - 212px);
    background-color: #fff;
    padding: 24px 0 0 0;

    .list {
        height: calc(100% - 48px);
        padding: 0 30px;

        ::v-deep .el-table__body-wrapper {
            height: calc(100vh - 331px) !important;
            overflow-y: scroll;
        }


        // 表头样式
        ::v-deep .el-table__header th {
            background-color: #f0f6fd;
            color: #262626;
            font-size: 12px;
            font-weight: bold;
            text-align: center;

            // 表 body的td
            ::v-deep .el-table__body td {
                color: #595959;
                font-size: 12px;
            }
        }

        .urlBox {
            display: flex;
            flex-direction: column;

            .urlText {
                color: #409EFF;
                transition: 0.2s;



                &:hover {
                    opacity: 0.8;
                }
            }
        }


        .picBox {
            display: flex;
            justify-content: space-evenly;
            width: 300px;

            // overflow: scroll;

            .pic {
                width: 85px;
                height: 80px;

            }
        }

        .tagBox {
            display: inline-block;

            .tag {
                // width: 63px;
                padding: 8px 10px;
                height: 28px;
                font-size: 12px;
                display: flex;
                align-items: center;
                justify-content: center;
                border-radius: 4px;
                margin: 0 auto;

                .dian {
                    width: 4px;
                    height: 4px;
                    border-radius: 50%;
                    margin-right: 4px;
                }


                &.yellow {
                    background-color: #fffce8;
                    color: #f9aa0d;

                    .dian {
                        background-color: #f9aa0d;
                    }
                }

                // &.gery {
                //     background-color: #f7f8f8;
                //     color: #a8b0b6;

                //     .dian {
                //         background-color: #a8b0b6;
                //     }
                // }

                // //已派车 和运输中 样式
                // &.dispatched {
                //     background-color: #ecf5fe;
                //     color: #1890ff;

                //     .dian {
                //         background-color: #1890ff;
                //     }
                // }

                &.green {
                    background-color: #ebfef5;
                    color: #1acb7a;

                    .dian {
                        background-color: #1acb7a;
                    }
                }

                &.red {
                    background-color: #fde8e9;
                    color: #f5222d;

                    .dian {
                        background-color: #f5222d;
                    }
                }
            }

        }


    }

    .paginationBox {
        border-top: 1px solid #f0f0f0;
        width: 100%;
        background-color: #fff;
        display: flex;
        height: 48px;
        align-items: center;
        padding: 0 30px;

        .pagination {
            margin-left: auto;
        }
    }
}

.dialog {

    // 标题
    ::v-deep .el-dialog__header {
        border-bottom: 1px solid #f0f0f0;
        padding: 15px 20px;
        color: #262626;
        font-size: 14px;
        font-weight: bold;
        height: 50px;
    }

    ::v-deep .el-dialog__title {
        font-size: 14px;
        color: #303133;
        font-weight: bold;
    }

    //关闭图标
    ::v-deep .el-dialog__headerbtn .el-dialog__close {
        font-size: 15px;
    }

    ::v-deep .el-form-item__label {
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #262626;
    }

    ::v-deep .el-dialog__body {
        padding: 25px 50px 36px 22px;
    }

    .submitBtn {
        width: 80px;
        height: 36px;
        background: #1890FF;
        border-radius: 4px;
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;

        text-align: center;
        cursor: pointer;
        transition: 0.2s;

        &:hover {
            opacity: 0.8;
        }
    }

    .cancelBtn {
        width: 80px;
        height: 36px;

        text-align: center;
        border: 1px solid #D9D9D9;
        border-radius: 4px;
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #262626;
        cursor: pointer;
        transition: 0.2s;
        margin-right: 14px;

        &:hover {
            border-color: #1890FF;
            color: #1890FF;
        }
    }
}
</style>
  